package com.cll.learn.rpc.common.serializer;

import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 描述信息:
 * 使用FastJson进行对象的序列化和反序列化
 * @author CLL
 * @version 1.0
 * @date 2020/9/14 15:30
 */
public class JsonSerializable implements Serializable {

    private static final Logger logger = LoggerFactory.getLogger(JsonSerializable.class);

    @Override
    public <T> byte[] serializable(T object) {
        logger.info("===>>> serializable");
        return JSON.toJSONBytes(object);
    }

    @Override
    public <T> T deserializable(Class<T> clazz, byte[] byteData) {
        logger.info("===>>> deserializable");
        return JSON.parseObject(byteData, clazz);
    }
}
